package com.eight.clienthome.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.eight.clienthome.service.*;
import com.eight.clienthome.vo.AttentionVo;
import com.eight.common.pojo.*;
import com.eight.common.utils.OssUtil;
import com.eight.common.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.websocket.server.PathParam;
import java.util.List;

/**
 * @author 向文豪
 * @program: eight-education-parent
 * @description:
 * @date 2023/6/1 20:40
 */
@RestController
@RequestMapping("/home/qian")
@Api(tags = "客户端首页显示")
public class LinkController {

    @Autowired
    private ZoneSubjectService zoneSubjectService;
    @Autowired
    private BannerService bannerService;

    @Autowired
    private LinkService linkService;

    @Autowired
    private ArticleService articleService;
    @Autowired
    private HeadService headService;

    @Autowired
    private ZoneService zoneService;
    @Autowired
    private BottomArticleService bottomArticleService;

    @Autowired
    private EduTeacherService eduTeacherService;

    @Autowired
    private AttentionTeacherService attentionTeacherService;

    @Autowired
    private EduCourseService eduCourseService;

    @PostMapping("/uploadMsg")
    @ApiOperation("")
    public String uploadMsg(@PathParam("file") MultipartFile file){
        String path = OssUtil.uploadFile(file);
        return path;
    }

    @ApiOperation("友情链接")
    @GetMapping("/link/getQianLink")
    public Result getLink(){
        List<TbLink> all = linkService.findAll();
        return Result.success(all);
    }

    @ApiOperation("底部文章")
    @GetMapping("/bottomArticle/getQianAllBottomArticle")
    public Result getArticle(){

        List<TbBottomArticle> all = bottomArticleService.findAll();
        return Result.success(all);

    }

    @ApiOperation("头部导航")
    @GetMapping("/head/getAllHead")
    public Result getHead(){

        List<TbHeadNav> all = headService.findAll();
        return Result.success(all);
    }

    @ApiOperation("专区课程")
    @GetMapping("/zone/getAllQianZone")
    public Result getAllZone(){

        List<TbZone> all = zoneService.findAll();
        return Result.success(all);
    }

    @ApiOperation("图片轮播")
    @GetMapping("/banner/getQianBanner")
    public Result getAllBanner(){

        List<CrmBanner> all = bannerService.findAll();
        return Result.success(all);
    }


    @ApiOperation("文章详情")
    @PostMapping("/article/getAllQianArticle/{id}")
    public Result getAllArticle(@PathVariable String id){

        TbArticle byId = articleService.findById(id);
        return Result.success(byId);
    }

    @ApiOperation("课程分类")
    @GetMapping("/zone/getAllQianMenu")
    public Result getAllMenu(){
        List<ZoneSubject> all = zoneSubjectService.findAll();
        return Result.success(all);
    }

    @ApiOperation("个人信息中我的关注")
    @PostMapping("/shoucangTeacher/findAttentionTeacherById/{huiYuanId}")
    public Result findAttentionTeacher(@PathVariable String huiYuanId){
        List<EduTeacher> teacher = eduTeacherService.findTeacher(huiYuanId);
        return Result.success(teacher);
    }

    @ApiOperation("取消关注")
    @PostMapping("/shoucangTeacher/deleteAttentionTeacher")
    public Result deleteAttention(@RequestBody AttentionVo attentionVo){

        Integer integer = attentionTeacherService.deleteAttention(attentionVo);
        return Result.success(integer);

    }
    @ApiOperation("根据老师id查询老师信息")
    @PostMapping("/findTeacherByTeacherId/{teacherId}")
    public Result findTeacherByTeacherId(@PathVariable String teacherId){
        EduTeacher teacherByTeacherId = eduTeacherService.findTeacherByTeacherId(teacherId);
        return Result.success(teacherByTeacherId);
    }

    @ApiOperation("分页条件查询")
    @PostMapping("/findCourseByTeacherId/{pageCurrent}/{pageSize}")
    public Result findCourseByTeacherId(@PathVariable Integer pageCurrent,@PathVariable Integer pageSize,@RequestBody AttentionVo attentionVo ){
        Page<EduCourse> coursePage = eduCourseService.findCourseByTeacherId(pageCurrent, pageSize, attentionVo);
        return Result.success(coursePage);
    }

}
